import axios from 'axios';

let axiosInstance = axios.create({
    baseURL:'/',
    timeout:5000,
})

axiosInstance.defaults.withCredentials = true;

axiosInstance.interceptors.request.use(
    (success) => { return success; },
    (error) => {
        return { message : '请求错误' }
    }
);

axiosInstance.interceptors.response.use(
    (success) => { return success; },
    (error) => { return { message : '响应错误'} }
);

export default{
    get(url,param){
        let result = axios({
            method:'get', url, param, timeout:10000,
            headers:{
                'Content-TYpe' : 'application/json;charset=utf-8',
            }
        }).then( success => { return success.data; });
        return result
    },

    post(url,data){
        let result = axios({
            method:'post', data, timeout:10000,
            headers: {
                'Content-Type' : 'application/json;charset=utf-8',
            }
        }).then(success => { return success.data; })
        return result;
    }
}
